﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using estudent.Models;

namespace estudent.Controllers
{
    public class OsebniPodatkiController : Controller
    {
        estudentEnt db = null;

        //
        // GET: /OsebniPodatki/

        public ActionResult Index()
        {
            ViewData["navodilo"] = "Poiščite študenta, za katerega želite videti osebne podatke.";
            ViewData["namen"] = "osebniPodatki";

            return View("IskanjeStudent");
        }

        public ActionResult Podatki(string id)
        {
            db = new estudentEnt();

            var student = db.Studentis
                .Where(p => p.username == id)
                .Select(p => p)
                .FirstOrDefault();

            var stud = "<p><table width=100% border=0><tr><td width=32%></td><td width=68%></td></tr>";
            //osnovni podatki
            stud += "<tr><td colspan=2> <hr size=\"1\"> </td></tr>";
            stud += "<tr><td align=\"left\" colspan=2> &nbsp OSNOVNI PODATKI </td></tr>";
            stud += "<tr><td colspan=2> <hr size=\"1\"> </td></tr>";

            stud += "<tr><td align=\"left\"><b>IME: &nbsp</b></td><td>" + student.ime + "</td></tr>";
            stud += "<tr><td align=\"left\"><b>PRIIMEK: &nbsp</b></td><td>" + student.priimek + "</td></tr>";
            if (student.dpriimek != null)
                stud += "<tr><td align=\"left\"><b>DEKLIŠKI PRIIMEK: &nbsp</b></td><td> " + student.dpriimek + "</td></tr>";
            stud += "<tr><td align=\"left\"><b>VPISNA ŠTEVILKA: &nbsp</b></td><td>" + student.username + "</td></tr>";
            stud += "<tr><td align=\"left\"><b>DATUM ROJSTVA: &nbsp</b></td><td>" + student.datumRojstva.ToShortDateString() + "</td></tr>";
            stud += "<tr><td align=\"left\"><b>EMŠO: &nbsp</b></td><td>" + student.emso + "</td></tr>";
            stud += "<tr><td align=\"left\"><b>DAVČNA ŠTEVILKA: &nbsp</b></td><td>" + student.davcnaStevilka + "</td></tr>";
            //kontaktni podatki
            stud += "<tr><td colspan=2> <hr size=\"1\"> </td></tr>";
            stud += "<tr><td align=\"left\" colspan=2> &nbsp KONTAKTNI PODATKI </td></tr>";
            stud += "<tr><td colspan=2> <hr size=\"1\"> </td></tr>";

            stud += "<tr><td align=\"left\"><b>TELEFON: &nbsp</b></td><td>" + student.telefonskaSt + "</td></tr>";
            stud += "<tr><td align=\"left\"><b>E-MAIL: &nbsp</b></td><td>" + student.email + "</td></tr>";
            //naslov
            stud += "<tr><td colspan=2> <hr size=\"1\"> </td></tr>";
            stud += "<tr><td align=\"left\" colspan=2> &nbsp NASLOV </td></tr>";
            stud += "<tr><td colspan=2> <hr size=\"1\"> </td></tr>";

            stud += "<tr><td align=\"left\"><b>ULICA: &nbsp</b></td><td>" + student.ulica + " " + student.hisnaSt + "</td></tr>";
            stud += "<tr><td align=\"left\"><b>POŠTA &nbsp</b></td><td>" + student.SPoste.sPosta + " " + student.SPoste.imePosta + "</td></tr>";
            stud += "<tr><td align=\"left\"><b>OBČINA: &nbsp</b></td><td>" + student.SObcine.imeObcina + "</td></tr>";
            stud += "<tr><td align=\"left\"><b>DRŽAVA &nbsp</b></td><td>" + student.SDrzave.imeDrzava + "</td></tr>";
            //začasni naslov
            if (student.SPoste1 != null)
            {
                stud += "<tr><td colspan=2> <hr size=\"1\"> </td></tr>";
                stud += "<tr><td align=\"left\" colspan=2> &nbsp ZAČASNI NASLOV </td></tr>";
                stud += "<tr><td colspan=2> <hr size=\"1\"> </td></tr>";

                stud += "<tr><td align=\"left\"><b>ULICA: &nbsp</b></td><td>" + student.zacasnaUlica + " " + student.zacasnaHisnaSt + "</td></tr>";
                stud += "<tr><td align=\"left\"><b>POŠTA &nbsp</b></td><td>" + student.SPoste1.sPosta + " " + student.SPoste1.imePosta + "</td></tr>";
                stud += "<tr><td align=\"left\"><b>OBČINA: &nbsp</b></td><td>" + student.SObcine1.imeObcina + "</td></tr>";
            }
            //posebna potreba
            if (student.posebnaPotreba != null)
            if (student.posebnaPotreba != "")
            {
                stud += "<tr><td colspan=2> <hr size=\"1\"> </td></tr>";
                stud += "<tr><td align=\"left\" colspan=2> &nbsp POSEBNOSTI </td></tr>";
                stud += "<tr><td colspan=2> <hr size=\"1\"> </td></tr>";

                stud += "<tr><td align=\"left\"><b>POSEBNA POTREBA: &nbsp</b></td><td>" + student.posebnaPotreba + "</td></tr>";
            }
            //vpisi
            stud += "<tr><td colspan=2> <hr size=\"1\"> </td></tr>";
            stud += "<tr><td align=\"left\" colspan=2> &nbsp VPISI </td></tr>";
            stud += "<tr><td colspan=2> <hr size=\"1\"> </td></tr>";
            stud += "</table></p>";

            stud += "<p><p><table width=100% cellspacing='0' cellpadding='0' border=1><tr align='center'><th>Št.</th><th>Št. leto</th><th>Letnik</th><th>Smer</th><th>Vrsta</th><th>Način</th></tr>";

            var vpisi = db.Vpisis
                .Where(p => p.username == student.username)
                .OrderBy(p => p.letoVpisa);
            var i = 0;
            foreach (var ele in vpisi)
            {
                i++;
                var nacin = "Redno";
                if (!ele.redni)
                    nacin = "Izredno";

                stud += "<tr align='center'><td>" + i + "</td><td>" + ele.letoVpisa.Year + "/" + (ele.letoVpisa.Year + 1) + "</td><td>" + ele.idLetnikStudija + "</td><td>" + ele.SSmeri.imeSmer + "</td><td>" + ele.idVrstaVpisa + "</td><td>" + nacin + "</td></tr>";
            }


            stud += "</table></p></p>";
            ViewData["podatki"] = stud;

            return View("OsebniPodatki");
        }

    }
}
